package xijia.plus.docs.manage.all.controller;

import io.github.wslxm.springbootplus2.core.base.controller.BaseController;
import io.github.wslxm.springbootplus2.core.constant.BaseConstant;
import io.github.wslxm.springbootplus2.core.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import xijia.plus.docs.constant.RequestConst;
import xijia.plus.docs.manage.all.model.dto.DocInfoDTO;
import xijia.plus.docs.manage.all.model.dto.DocInfoUpdHtmlDTO;
import xijia.plus.docs.manage.all.model.query.DocInfoQuery;
import xijia.plus.docs.manage.all.model.vo.DocInfoVO;
import xijia.plus.docs.manage.all.service.DocInfoService;

import java.util.List;

/**
 * 文档表 前端控制器
 *
 * <p>
 * ::本代码由[兮家小二]提供的代码生成器生成,如有问题,请手动修改 ::作者CSDN:https://blog.csdn.net/qq_41463655
 * </p>
 *
 * @author ws
 * @email 1720696548@qq.com 解析
 * @date 2022-10-18 15:11:33
 */
@RestController
@RequestMapping(BaseConstant.Uri.API_ADMIN + "/all/docInfo")
@Api(value = "DocInfoController", tags = "文档表")
public class DocInfoController extends BaseController<DocInfoService> {

    @GetMapping(value = "list/keyData")
    @ApiOperation(value = "关键数据查询")
    public Result<List<DocInfoVO>> listKeyData(@ModelAttribute @Validated DocInfoQuery query) {
        return Result.success(baseService.listKeyData(request.getHeader(RequestConst.DB), query));
    }

    @GetMapping(value = "/tree")
    @ApiOperation(value = "列表查询")
    public Result<List<DocInfoVO>> tree(@ModelAttribute @Validated DocInfoQuery query) {
        return Result.success(baseService.tree(request.getHeader(RequestConst.DB), query));
    }

    @GetMapping(value = "/listIdNames")
    @ApiOperation(value = "只查询数据的id/名称")
    public Result<List<DocInfoVO>> listIdNames() {
        return Result.success(baseService.listIdNames(request.getHeader(RequestConst.DB)));
    }


    @GetMapping(value = "/{id}")
    @ApiOperation(value = "ID查询")
    public Result<DocInfoVO> findId(@PathVariable String id) {
        return Result.success(baseService.findId(request.getHeader(RequestConst.DB), id));
    }

    @PostMapping
    @ApiOperation(value = "添加")
    public Result<String> insert(@RequestBody @Validated DocInfoDTO dto) {
        return Result.successInsert(baseService.insert(request.getHeader(RequestConst.DB), dto));
    }

    @PutMapping(value = "/{id}")
    @ApiOperation(value = "ID编辑")
    public Result<Boolean> upd(@PathVariable String id, @RequestBody @Validated DocInfoDTO dto) {
        return Result.successUpdate(baseService.upd(request.getHeader(RequestConst.DB), id, dto));
    }


    @PutMapping(value = "/updHtml/{id}")
    @ApiOperation(value = "ID编辑")
    public Result<Boolean> updHtml(@PathVariable String id, @RequestBody DocInfoUpdHtmlDTO docInfoUpdHtmlDTO) {
        return Result.successUpdate(baseService.updHtml(request.getHeader(RequestConst.DB), id, docInfoUpdHtmlDTO));
    }


    @PutMapping(value = "/updPid/{id}")
    @ApiOperation(value = "变更父级")
    public Result<Boolean> updPid(@PathVariable String id, @RequestParam String pid) {
        return Result.successUpdate(baseService.updPid(request.getHeader(RequestConst.DB), id, pid));
    }


    @PutMapping(value = "/updDisable/{id}")
    @ApiOperation(value = "启用/禁用")
    public Result<Boolean> updDisable(@PathVariable String id, @RequestParam Integer disable) {
        return Result.successUpdate(baseService.updDisable(request.getHeader(RequestConst.DB), id, disable));
    }

    @PutMapping(value = "/updSort/{id}")
    @ApiOperation(value = "启用/禁用")
    public Result<Boolean> updSort(@PathVariable String id, @RequestParam Integer sort) {
        return Result.successUpdate(baseService.updSort(request.getHeader(RequestConst.DB), id, sort));
    }


    @DeleteMapping(value = "/{id}")
    @ApiOperation(value = "ID删除")
    public Result<Boolean> del(@PathVariable String id) {
        return Result.successDelete(baseService.del(request.getHeader(RequestConst.DB), id));
    }


    @DeleteMapping(value = "/delByType")
    @ApiOperation(value = "删除指定分类下的文档")
    public Result<Boolean> delByType(@RequestParam Integer type) {
        return Result.success(baseService.delByType(request.getHeader(RequestConst.DB), type));
    }
}
